package mamma.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import mamma.dao.BabyDao;
import mamma.vo.BabyDailyVo;
import mamma.vo.BabyInfoVo;
import mamma.vo.MemberVo;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BabyAction extends ActionSupport {
	
	private int babynum;
	private String name;
	private String sex;
	private String borndate;
	private String bornweek;
	private String deliveryinfo;
	private String birthtype;
	private String birthlocation;
	private String inputdate;
	private String loginId;
	private String email;
	
	private int headsize;
	private int height;
	private int weight;
	
	private BabyInfoVo 	baby;
	private MemberVo memberVo;
	
	private int 		num;
	
	private List<BabyInfoVo> list;
	
	// ==============================
	
	private int dailynum;
	private int suyu;
	private int sobyun;
	private int play;
	private int suyuamount;
	private int liyusik;
	private int bochaegi;
	private int ungga;
	private int sleeptime;
	private int diapers;
	
	private BabyDailyVo babyData;
	
	private String starttime;
	
	private String memo;
	
	private List<BabyDailyVo> dailyList;
	
	
	public String baby() throws Exception {
		System.out.println("아기 정보 입력 =================baby insert start");
		ActionContext context = ActionContext.getContext();
		Map<String, Object>session = (Map<String, Object>)context.getSession();
		MemberVo email = (MemberVo)session.get("login");
		loginId = email.getEmail();
		
		BabyDao dao = new BabyDao();
		BabyInfoVo babyInfo = new BabyInfoVo();
		
		babyInfo.setMemberemail(loginId);
		babyInfo.setName(name);
		babyInfo.setSex(sex);
		babyInfo.setBorndate(borndate.replace('-', '/'));
		babyInfo.setBornweek(bornweek);
		babyInfo.setDeliveryinfo(deliveryinfo);
		babyInfo.setBirthtype(birthtype);
		babyInfo.setBirthlocation(birthlocation);
		
		babyInfo.setInputdate(borndate);
		babyInfo.setHeadsize(headsize);
		babyInfo.setHeight(height);
		babyInfo.setWeight(weight);
		
		
		System.out.println(babyInfo);
		dao.insertBaby(babyInfo);
		
		return SUCCESS;
		
	}
	
	public String selectBabyList(){
		System.out.println("selectBabyList method activated");
		
		BabyDao dao = new BabyDao();
		BabyInfoVo vo = new BabyInfoVo();
		vo.setMemberemail(loginId);
		list = dao.selectBabyList(vo);
		
		return SUCCESS;
	}
	
	
	// ================ baby info
	
	public String goBabyInfo(){
		System.out.println("goBabyInfo method activated");
		
		ActionContext context = ActionContext.getContext();
		Map<String, Object> session = context.getSession();
		memberVo = (MemberVo)session.get("login");
		loginId = memberVo.getEmail();
		
		BabyDao dao = new BabyDao();
		list = dao.goBabyInfo(loginId);
		
		return SUCCESS;
	}
	
	public String goBabyDaily(){
		System.out.println("goBabyDaily method activated");
		
		ActionContext context = ActionContext.getContext();
		Map<String, Object> session = context.getSession();
		memberVo = (MemberVo)session.get("login");
		loginId = memberVo.getEmail();
		
		BabyDao dao = new BabyDao();
		list = dao.goBabyInfo(loginId);
		
		return SUCCESS;
	}
	
	
	
	//입력
	public String insertBabyInfo(){

		BabyInfoVo baby = new BabyInfoVo();
		baby.setBabynum(babynum);
		baby.setHeight(height);
		baby.setWeight(weight);
		baby.setHeadsize(headsize);
		baby.setInputdate(inputdate);
		System.out.println(baby);
		BabyDao dao = new BabyDao();
		dao.insertBabyInfo(baby);

		return SUCCESS;
	}

	//목록
	public String listBabyInfo(){
		BabyDao dao = new BabyDao();
		list = dao.listBabyInfo(num);

		return SUCCESS;
	}

	//목록(3개만 보여주기_Home화면)
	public String listBabyInfoThree(){
		BabyDao dao = new BabyDao();
		list = dao.listBabyInfoThree(babynum);

		return SUCCESS;
	}
	
	// =========================================
	//데이터 입력
	public String insertBabyData(){
		inputdate = inputdate.replaceAll("-", "");
		starttime = starttime.replaceAll(":", "");

		BabyDailyVo baby = new BabyDailyVo();
		baby.setSuyu(suyu);
		baby.setSobyun(sobyun);
		baby.setPlay(play);
		baby.setInputdate(inputdate);
		baby.setSuyuamount(suyuamount);
		baby.setLiyusik(liyusik);
		baby.setBochaegi(bochaegi);
		baby.setUngga(ungga);
		baby.setSleeptime(sleeptime);
		baby.setDiapers(diapers);
		baby.setStarttime(inputdate+starttime);

		baby.setMemo(memo);
		baby.setBabynum(babynum);
		System.out.println(inputdate);
		System.out.println(starttime);
		System.out.println(baby.getStarttime());
		BabyDao dao = new BabyDao();
		dao.insertBabyData(baby);

		return SUCCESS;
	}

	//데이터 출력
	public String listBabyData(){
		System.out.println("inputdate:" +inputdate+"||");
		BabyDao dao = new BabyDao();
		BabyDailyVo vo = new BabyDailyVo();
		vo.setBabynum(babynum);
		vo.setInputdate(inputdate);
		
		babyData = dao.listBabyData(vo);
		
		System.out.println(babyData);

		return SUCCESS;
	}

	
	// ============ getter & setter ============
	public int getBabynum() {
		return babynum;
	}


	public void setBabynum(int babynum) {
		this.babynum = babynum;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getSex() {
		return sex;
	}


	public void setSex(String sex) {
		this.sex = sex;
	}


	public String getBorndate() {
		return borndate;
	}


	public void setBorndate(String borndate) {
		this.borndate = borndate;
	}


	public String getBornweek() {
		return bornweek;
	}


	public void setBornweek(String bornweek) {
		this.bornweek = bornweek;
	}


	public String getDeliveryinfo() {
		return deliveryinfo;
	}


	public void setDeliveryinfo(String deliveryinfo) {
		this.deliveryinfo = deliveryinfo;
	}


	public String getBirthtype() {
		return birthtype;
	}


	public void setBirthtype(String birthtype) {
		this.birthtype = birthtype;
	}


	public String getBirthlocation() {
		return birthlocation;
	}


	public void setBirthlocation(String birthlocation) {
		this.birthlocation = birthlocation;
	}

	public int getHeadsize() {
		return headsize;
	}


	public void setHeadsize(int headsize) {
		this.headsize = headsize;
	}


	public int getHeight() {
		return height;
	}


	public void setHeight(int height) {
		this.height = height;
	}


	public int getWeight() {
		return weight;
	}


	public void setWeight(int weight) {
		this.weight = weight;
	}


	public String getInputdate() {
		return inputdate;
	}


	public void setInputdate(String inputdate) {
		this.inputdate = inputdate;
	}


	public BabyInfoVo getBaby() {
		return baby;
	}


	public void setBaby(BabyInfoVo baby) {
		this.baby = baby;
	}


	public int getNum() {
		return num;
	}


	public void setNum(int num) {
		this.num = num;
	}


	public List<BabyInfoVo> getList() {
		return list;
	}


	public void setList(List<BabyInfoVo> list) {
		this.list = list;
	}


	public MemberVo getMemberVo() {
		return memberVo;
	}

	public void setMemberVo(MemberVo memberVo) {
		this.memberVo = memberVo;
	}

	public String getLoginId() {
		return loginId;
	}
	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}

	public int getDailynum() {
		return dailynum;
	}

	public void setDailynum(int dailynum) {
		this.dailynum = dailynum;
	}

	public int getSuyu() {
		return suyu;
	}

	public void setSuyu(int suyu) {
		this.suyu = suyu;
	}

	public int getSobyun() {
		return sobyun;
	}

	public void setSobyun(int sobyun) {
		this.sobyun = sobyun;
	}

	public int getPlay() {
		return play;
	}

	public void setPlay(int play) {
		this.play = play;
	}

	public int getSuyuamount() {
		return suyuamount;
	}

	public void setSuyuamount(int suyuamount) {
		this.suyuamount = suyuamount;
	}

	public int getLiyusik() {
		return liyusik;
	}

	public void setLiyusik(int liyusik) {
		this.liyusik = liyusik;
	}

	public int getBochaegi() {
		return bochaegi;
	}

	public void setBochaegi(int bochaegi) {
		this.bochaegi = bochaegi;
	}

	public int getUngga() {
		return ungga;
	}

	public void setUngga(int ungga) {
		this.ungga = ungga;
	}

	public int getSleeptime() {
		return sleeptime;
	}

	public void setSleeptime(int sleeptime) {
		this.sleeptime = sleeptime;
	}

	public int getDiapers() {
		return diapers;
	}

	public void setDiapers(int diapers) {
		this.diapers = diapers;
	}

	public BabyDailyVo getBabyData() {
		return babyData;
	}

	public void setBabyData(BabyDailyVo babyData) {
		this.babyData = babyData;
	}

	public String getStarttime() {
		return starttime;
	}

	public void setStarttime(String starttime) {
		this.starttime = starttime;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public List<BabyDailyVo> getDailyList() {
		return dailyList;
	}

	public void setDailyList(List<BabyDailyVo> dailyList) {
		this.dailyList = dailyList;
	}
	
}
